﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using MESGateWay.Common;
using System.Configuration;
using MESGateWay.Business;

namespace MESGateWay.WinSMESContainer
{
    partial class Send_MESContainer : ServiceBase
    {
        public Send_MESContainer()
        {
            InitializeComponent();
        }

        private System.Timers.Timer m_SyncTimer;
        protected override void OnStart(string[] args)
        {
            LogHelp.SetConfig();
            m_SyncTimer = new System.Timers.Timer();
            m_SyncTimer.Enabled = false;
            m_SyncTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_SyncTimer_Elapsed);

            int intSync = Convert.ToInt32(ConfigurationManager.AppSettings["sync"].ToString());
            m_SyncTimer.Interval = intSync *60* 1000;
            m_SyncTimer.Enabled = true;
            m_SyncTimer.Start();
        }
        private void m_SyncTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                LogHelp.WriteLog("Container定时器启动");
                m_SyncTimer.Enabled = false;
                SendDataToERP runMain = new SendDataToERP();
                runMain.RunContainerSync();
            }
            catch (Exception myError)
            {
                LogHelp.WriteError("Container定时器启动", myError);
            }
            finally
            {
                m_SyncTimer.Enabled = true;
            }
        }

        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
        }

   }
}
